/**
 * 
 */
package cn.gov.msa.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;

import com.github.pagehelper.PageHelper;

import cn.gov.msa.dao.MenuMapper;
import cn.gov.msa.model.Menu;
import cn.gov.msa.pagehelper.CustomPageHelper;
import cn.gov.msa.service.MenuService;

/**
 * @author Administrator
 *
 */
public class MenuServiceImpl implements MenuService {

	@Autowired
	private MenuMapper menuMapper;

	@Override
	public List<Menu> findLeftMenu(String menufid) throws Exception {
		
		List<Menu> menuFList = new ArrayList<Menu>();
		
		menuFList = menuMapper.findLeftMenu(menufid);
		
		return menuFList;
	}
	
	@Cacheable(value="dzzw_cache",key="'queryLeftMenu'.concat(#userId)",unless="#result.size() <= 0")
	@Override
	public List<Menu> queryLeftMenu(String userId)throws Exception{
		List<Menu> menuFList = new ArrayList<Menu>();
		menuFList = menuMapper.queryMenu(userId);
		return menuFList;
	}

	public List<Menu> findMenu(int pageNum, int pageSize, Menu menu) throws Exception {
		
		CustomPageHelper.startPage(pageNum, pageSize); // 核心分页代码  
		List<Menu> listMenus = menuMapper.findMenu(menu);
		
		return listMenus;
	}

	
	public int deleteByPrimaryKey(String menuid) throws Exception {
		
		int result = menuMapper.deleteByPrimaryKey(menuid);
		
		return result;
	}

	
	public boolean saveData(Menu menu) throws Exception {
		boolean result = false;
		int idict = menuMapper.insert(menu);
		if(idict > 0){
			result = true;
		}
		return result;
	}

	@Override
	public List<Menu> selectFid() throws Exception {
		
		List<Menu> listMenus = menuMapper.selectFid();
		
		return listMenus;
	}

	@Override
	public List<Menu> selectChild() throws Exception {
		
		List<Menu> listMenus = menuMapper.selectChild();
		
		return listMenus;
	}

	@Override
	public boolean updateData(Menu menu) throws Exception {
		
		boolean result = false;
		
		int imenu = menuMapper.updateByPrimaryKeySelective(menu);
		
		if(imenu > 0)
			result = true;
		
		return result;
	}

	@Override
	public List<Menu> selectFidOne(String name) throws Exception {
		
		List<Menu> menu = menuMapper.selectFidOne(name);
		return menu;
	}

	@Override
	public Menu selectName(String menufid) throws Exception {
		Menu menu = menuMapper.selectName(menufid);
		return menu;
	}

}
